<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
    /**
     * 登录
     */
    public function index() {
        if (IS_POST) {
            $M_hospital = M('hospital');
            $where['phone']      = I('post.phone');
            $where['password']   = md5(I('post.password'));
            $is_hos = $M_hospital->where($where)->find();
            if($is_hos){
                cookie('uid',$is_hos['id'],31536000);
                cookie('phone',$is_hos['phone'],31536000);
                $return     = array('code'=>0,'msg'=>'登录成功！','url'=>U('Index/index'));
                $this->ajaxReturn($return,'json');
            }else{
                $return     = array('code'=>-1,'msg'=>'账号或密码错误');
                $this->ajaxReturn($return,'json');
            }
        } else {
            $this->display();
        }
    }
    /**
     * 退出登录
     */
    public function logout() {
        cookie('uid', null);
        $return = array("code"=>0,"msg" => '退出成功！','url'=>U('Login/index'));
        $this->ajaxReturn($return,'JSON');exit;
    }
}